<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 80px">订单号:</label>
        <div class="layui-input-inline" style="width:12%">
            <input type="text" name="billNo" id="billNo" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width:80px">用户手机:</label>
        <div class="layui-input-inline" style="width:8%">
            <input type="text" name="account" id="account" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 60px;margin-left: 5px">状态:</label>
        <div class="layui-input-inline" style="width: 6%">
            <select name="status" id="status">
                <option value="">全部</option>
                <option value="1">待处理</option>
                <option value="2">已处理</option>
                <option value="3">未通过</option>
            </select>
        </div>
        <label class="layui-form-label" style="width: 80px">创建时间:</label>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeSt" name="addTimeSt">
        </div>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeEt" name="addTimeEt">
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <a id="down" class="layui-btn layui-btn-radius" download="提现订单.csv" href="#">提现订单导出</a>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var tableIns;
    var allStr;

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeSt', //指定元素
            format: 'yyyy-MM-dd'
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeEt', //指定元素
            format: 'yyyy-MM-dd'
        });

    });

    $('#down').on('click', function (aLink) {
        var table = layui.table;
        var tab = allStr;
        var str = "提现订单号,交易凭证号,用户昵称,用户手机,金额,审核状态,申请提现时间\n";
        var statusStr = "";
        $.each(tab, function (i, row) {
            if (row["status"] == "1") {
                statusStr = "未处理";
            } else if (row["status"] == "2") {
                statusStr = "已处理";
            } else if (row["status"] == "3") {
                statusStr = "未通过";
            }

            str = str + row["billNo"] + "," + "JY" + row["tradeNo"] + "," + row["nickName"] + "," + row["account"] + "," +
                "" + row["fee"] + "," + statusStr + "," + row["createTime"] + "\n";
        });
        str = encodeURIComponent(str);
        aLink.target.href = "data:text/csv;charset:utf-8,\ufeff" + str;
    });

    $(function () {
        tableIns = createTable({
            url: 'withdrawBillList',
            cols: [[
                {
                    field: 'billNo',
                    title: '提现订单号',
                    width: 200
                },
                {
                    field: 'tradeNo',
                    title: '交易凭证号',
                    width: 200
                },
                {
                    field: 'nickName',
                    title: '用户昵称',
                    width: 180
                }, {field: 'account', title: '用户手机', width: 180}, {
                    field: 'fee',
                    title: '金额',
                    width: 150
                }, {
                    field: 'status',
                    title: '审核状态',
                    width: 100, templet: '#statusTpl'
                }, {
                    field: 'createTime',
                    title: '申请提现时间',
                    width: 180
                }, {
                    fixed: 'right',
                    title: '操作',
                    width: 450,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]], height: 'full-130'
        });

        $.post('/backend/security/withdrawBill/withdrawBillList', function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
    })
    ;

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象

        if (layEvent === 'tradeInfo') { //查看
            openDialog({
                url: "/backend/security/withdrawBill/detail?id=" + data.id,
                area: ["55%", "65%"]
            });
        } else if (layEvent === 'billInfo') { //查看
            openDialog({
                url: "/backend/security/withdrawBill/billList?id=" + data.id + "&customerId=" + data.customerId,
                area: ["95%", "85%"]
            });
        } else if (layEvent === 'fail') { //查看
            layer.confirm('确认这比提现不通过审核?', function (index) {
                $.post('/backend/security/withdrawBill/commissionFail', {
                    id: data.id
                }, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg('操作成功');
                        layui.table.reload("grid");
                    }
                });
            })
        }
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });

        $.post('/backend/security/withdrawBill/withdrawBillList', {
            billNo: $("#billNo").val(),
            account: $("#account").val(),
            status: $("#status").val(),
            addTimeSt: $("#addTimeSt").val(),
            addTimeEt: $("#addTimeEt").val()
        }, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
        return false;
    });
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===3){ }}
    <span style="color: #FF0000;">未通过</span>
    {{#  } else  if(d.status ===2){ }}
    <span style="color: green;">已处理</span>
    {{#  } else  if(d.status ===1){ }}
    <span>未处理</span>
    {{#  } }}
</script>
<script type="text/html" id="opbar">
    {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="tradeInfo">输入付款凭证号以确认提现</a>
    <a class="layui-btn layui-btn-xs" lay-event="fail">未通过审核</a>
    {{# } }}
    {{# if(d.status<3){ }}
    <a class="layui-btn layui-btn-xs" lay-event="billInfo">查看关联订单</a>
    {{# } }}
</script>
</body>
</html>
